home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1994 / MacHack 1994.toast / MacHack™94 / Miscellaneous / Randy Thelen / ThreadedSort / Misc Stuff / Exceptions.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-26  |  1.9 KB  |  80 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        Exceptions.h
  3.  
  4.     Contains:    exception handling macros
  5.                 Brutally stolen from the Finder 7.1 sources
  6.                 Brutally restolen from the Star Trek runtime stuff
  7.  
  8.     Written by:    Bruce Horn, Steve Capps, Larry Kenyon,
  9.                 John Meier, scott douglass, Darin Adler,
  10.                 Paul Mercer, Bryan Stearns, Dave Owens, Alan Mimms
  11.  
  12.     Copyright:    © 1988-1990, 1993 by Apple Computer, Inc., all rights reserved.
  13.  
  14.     Change History (most recent first):
  15.  
  16.          <1>    10/11/93    DRF        Miss Manners + MW mangling
  17.          <1>     6/15/93    ABM        first checked in
  18.          <4>     12/3/92    dho        reinclude CDStackFrame* back into our TException class
  19.          <3>     9/30/92    dho        move exceptions data out of partition globals
  20.          <2>     9/15/92    dho        make include quoting exact
  21.         <2+>     8/27/92    dho        8.3
  22.          <2>     8/17/92    dho        use setJmp and longJmp for exception handling
  23.          <1>     7/24/92    dho        First checked in for Star Trek
  24.         <3+>     3/27/90    sad        guard #includes
  25.         12/15/89    sad        suppress value no used warning from NOREGISTER
  26.         10/2/89        sad        add extern "C"; add savedCDStackPtr to exceptions_tFailInfo;
  27.                                 added exceptions_FailAgain
  28.         4/29/89        BJS        add NOREGISTER
  29.         9/11/88        JRM        incluse moretypes
  30.         9/10/88        dba        add FailAgain and ExpectError macros
  31.         8/29/88        dba        added Fail
  32.         8/19/88        dba        added FailMemError, FailResError, and FailResourceNil
  33.         7/21/88        JRM        add FailErr and FailNil
  34.         7/15/88        JRM        received version from Andy Heninger
  35.         7/5/88        AH        Revise to work with plain C as well as C++
  36.         6/27/88        AH        Initial Version
  37.  
  38.     To Do:
  39. */
  40.  
  41. #ifndef _EXCEPTIONS_
  42. #define _EXCEPTIONS_
  43.  
  44. #include <Types.h>
  45. #include <setjmp.h>
  46.  
  47.  
  48. class TException
  49. {
  50. public:
  51.                         TException();
  52.                         ~TException();
  53.                         
  54.     void                Pop(void);
  55.     
  56.     jmp_buf             fEnv;
  57.     TException *        fNext;
  58. };
  59.  
  60.  
  61. void    Fail(void);
  62.  
  63. inline void FailIf (int cond)
  64. {
  65.     if (cond) Fail();
  66. }
  67.  
  68. inline void FailNil(void *p)
  69. {
  70.     if (p == nil)
  71.         Fail();
  72. }
  73.  
  74. #define TRY        { TException exceptionData;    if (setjmp(exceptionData.fEnv) == 0) {
  75. #define EXCEPT    } else {
  76. #define ENDTRY    } exceptionData.Pop(); }
  77.  
  78.  
  79. #endif
  80.